package com.pipayshop.task;

import com.pipayshop.entity.vo.ResponseVO;
import com.pipayshop.exception.BusinessException;
import com.pipayshop.service.OnlineStoreShopOrderInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * @author xiaoqiu
 * @date 2024/10/10 10:25
 * @description
 */
@Component
@Slf4j
public class OnlineStoreOrderTask {

    @Autowired
    private OnlineStoreShopOrderInfoService shopOrderInfoService;

    /**
     定时轮询删除失效订单接口
     */
    @Scheduled(cron = "0 */1 * * * ?")
    public ResponseVO<String> deleteFailOrders() {
        try {
            shopOrderInfoService.deleteFailOrders();
            System.out.println("定时轮询删除失效订单成功");
            return ResponseVO.getSuccessResponseVo("定时轮询删除失效订单成功");
        } catch (Exception e) {
            log.error(e.getMessage());
            throw new BusinessException("定时轮询删除失效订单失败，请联系后台人员");
        }
    }
}
